﻿<%@ page pageEncoding="UTF-8"%>
<%@include file="/util/tag.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <%@include file="../common/head.jsp"%>

        <script language="javascript" type="text/javascript">
            //保存成功的提示消息
            function showResult() {
                showResultDiv(true);
                window.setTimeout("showResultDiv(false);", 3000);
            }
            function showResultDiv(flag) {
                var divResult = document.getElementById("save_result_info");
                if (flag)
                    divResult.style.display = "block";
                else
                    divResult.style.display = "none";
            }
            $(function(){
            $("#roleForm").validate({
            	rules:{
            	"role.name":"required",
            	"role.pid":"required"
            	},messages:{
            		"role.name":"不能为空",
            		"role.pid":"至少选择一个"
            	},errorPlacement:function(error,element) {
            	var p = $(element).parents("ul");
            		if(p.length>0){
            			element = p.eq(0).parent().eq(0);
            		}
            		
            		 error.appendTo(element.siblings(":last").addClass("error_msg"));
            	},success:function(label,element){
            		var p = $(element).parents("ul");
            		if(p.length>0){
            			element = p.eq(0).parent().eq(0);
            		}
            		 	$(element).siblings(":last").removeClass("error_msg").empty();
            		 }
            });
            	$('#save').click(function(){
            	if(!$("#roleForm").valid()) return;
            		var b=$("#roleForm").submitForm("save",
            			"保存失败，角色名称重复！",'保存成功!',$("#save_result_info"));
            			if(b){
            				$('#save_result_info').attr("class","save_success");
            			}else{
            				$('#save_result_info').attr("class","save_fail");
            			}
            			showResult();
            	});
            });
        </script>
        
    <body>
        <%@include file="../common/top.jsp"%>
	
        <div id="main">            
            <!--保存操作后的提示信息：成功或者失败-->
            <div id="save_result_info" class="save_success">保存成功！</div><!--保存失败，角色名称重复！-->
            <form action="save" method="post" class="main_form" id="roleForm">
                <div class="text_info clearfix"><span>角色名称：</span></div>
                <div class="input_info">
                    <input type="text" class="width200" name="role.name"/>
                    <span class="required">*</span>
                    <div class="validate_msg_medium"></div>
                </div>                    
                <div class="text_info clearfix"><span>设置权限：</span></div>
                <div class="input_info_high">
                    <div class="input_info_scroll">
                        <ul>
                        	<s:iterator value="privileges">
                            <li><input type="checkbox" name="role.pid" value="${id}"/>${name}</li>
                        	</s:iterator>
                        </ul>
                    </div>
                    <span class="required">*</span>
                    <div class="validate_msg_tiny"></div>
                </div>
                <div class="button_info clearfix">
                    <input type="button" value="保存" class="btn_save" id="save" />
                    <input type="button" value="取消" class="btn_save" onclick="location.href='list?page=${page}'"/>
                </div>
            </form>
        </div>
        
        <%@include file="../common/bottom.jsp"%>
    </body>
</html>
